package bosVM2.meta.Objects;

import bosVM2.FaultHandling.AnCodeFaultHandler;
import bosVM2.meta.LookUp;
import bosVM2.util.Map;

public class BosObject {
	
	//Faulthandler
	AnCodeFaultHandler an = AnCodeFaultHandler.getAnFaultHAndler();
	private BosClass clss;
	private Map<String, Object> fields;

	public BosObject(BosClass clss) {
		fields = new Map<String,Object>();
		for(String s: clss.getFields()) {
			fields.put(s, null);
		}
		this.clss = clss;
	}
	 
	public BosClass Class()
	{
		return clss;
	}
	
	public String toString()
	{
		return fields.Entries() + " " + clss;
	}
	
	public void putfield(String field, Object o)
	{		
		fields.put(field, o);
		fields.put(field+"coded",an.enCode((Integer) o));
	}
	
	public Object getField(String field)
	{
		if(an.valid(((Integer) fields.get(field+"coded"))))
		{
			return fields.get(field);
		}
		else 
		{
			return (an.deCode((Integer) fields.get(field+"coded")));
		}
	}

}
